<?php 
namespace Home\Model;
use Think\Model;

class UserModel extends Model{
	protected $trueTableName='user';
	public function register($user,$pwd){
          if (isset($user)&&isset($pwd)) {
          	  $condition['username']=$user;
       $res=$this->where($condition)->count();
       //查看用户名的数量
         if($res==0){
                $data['username']=$user;
          	    $data['password']=$pwd;
          	    $this->add($data);
          	    return 1;
          	    //注册成功
          	}
          	 return 2;   
          	 //用户名已存在
          }else{
          	//参数没有设置
          	return false;

          }
	}
     public function isExist($username){
           $condition['username']=$username;
           $status=$this->where($condition)->getField("status");
           return $status;
     }
     //得到status字段
	public function login($user,$pwd){
          if (isset($user)&&isset($pwd)) {
            $status=$this->isExist($user);
               if($status==0){
               $condition['username']=$user;
               $condition['password']=$pwd;
               $res=$this->where($condition)->count();
               if($res==1){
                //登录成功
                return 1;
               }else{
                //用户名密码不匹配
                return 2;
               }
               }else{
                return 2; 
               }
          	   
          }

          else{
          	//参数没有设置
          	return false;
          }
	}
}
 ?>
